<template>
	<view class="p-home">
		<picker class="hotel-top" @change="bindPickerChange" :value="HoList[active].id" :range="array" v-if="!order_id">
			<view style="display: flex;height: 100%;line-height: 100rpx;">
				<view class="uni-input ellipsis1" style="flex: 1;">{{HoList[active].hotel_name}}</view>
				<view class="hotel-cut">切换 ></view>
			</view>
		</picker>
		<view class="hotel-title" v-if="order_id">
			{{info.hotel_name}}
		</view>
		<view class="place-top">
			<view class="place-start">
				开始日
				<picker class="picker" mode="date" :value="startDay" :start="startDate" :end="endDate" @change="startDayChange">
					<view class="uni-input">{{startDay}}</view>
				</picker>
			</view>
			<view class="place-text">共{{num}}天</view>
			<view class="place-end">
				结束日
				<picker class="picker" mode="date" :value="endDay" :start="startDate" :end="endDate" @change="endDayChange">
					<view class="uni-input">{{endDay}}</view>
				</picker>
			</view>
		</view>
	
		<view class="from-box">
			<view class="from-item">
				<view class="from-title">模块</view>
				<view class="from-small isflex">
					<view style="flex: 1;"></view>
					<view class="from-small-left isflex" style="width: 100%;">
						<view v-for="(item,index) in classList" :key="index" class="wage-item" 
							:class="order_class==index?'active':''" @tap="cutSlass(index)">
							{{item}}
						</view>
					</view>
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">职位</view>
				<view class="from-small">
					<picker class="xuan" @change="bindPickerZhi" :value="acZhi" :range="zhi">
						<view class="uni-input">{{zhiList[acZhi].name}}</view>
					</picker>
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">联系人电话</view>
				<view class="from-small">
					<input type="number" maxlength="11" v-model="mobile" placeholder="请输入电话">
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">联系人姓名</view>
				<view class="from-small">
					<input type="text" v-model="name" placeholder="请输入联系人姓名">
				</view>
			</view>
			<view class="from-item" v-if="zhiType==2">
				<view class="from-title">上班时间</view>
				<view class="from-small isflex">
					<view class="from-small-left isflex">
						<view v-for="(item,index) in timeList" :key="index" class="wage-item" 
							:class="duty_time_type==index+1?'active':''" @tap="cutTime(index)">
							{{item}}
						</view>
					</view>
					<view style="flex: 1;" @tap="isShow = true" v-if="duty_time_type==1">
						<view class="" v-if="duty_time">{{duty_time}}</view>
						<view class="" v-else>请选择</view>
					</view>
					<view style="display: flex;flex: 1;" v-else>
						<picker style="flex: 1;" mode="multiSelector" :value="duty_time" :range="shangTime" @change="bindShangChange">
							<view class="uni-input" v-if="duty_time">{{duty_time}}</view>
							<view class="uni-input" v-else>请选择</view>
						</picker>
						<input style="height: 100rpx;width: 150rpx;" type="digit" v-model="time" placeholder="预计时长">
					</view>
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">到岗时间</view>
				<view class="from-small">
					<picker mode="multiSelector" :value="work_time" :range="daoTime" @columnchange="changeTime" @change="bindTimeChange">
						<view class="uni-input" v-if="work_time">{{work_time}}</view>
						<view class="uni-input" v-else>请选择</view>
					</picker>
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">需求人数</view>
				<view class="from-small isflex">
					<view class="from-small-left" v-if="zhiType==2">
						区分性别
						<switch color="#26c87d" @change="changeSex" :checked="gender_require==1" style="transform:scale(0.7)"/>
					</view>
					<view style="flex: 1;" v-if="zhiType==2">
						<input type="number" v-if="gender_require==0" v-model="people_number" placeholder="请输入人数">
						<view class="isflex" v-else>
							<input type="number" v-model="man_number" placeholder="人数"> 男
							<input type="number" v-model="woman_number" placeholder="人数"> 女
						</view>
					</view>
					<view style="flex: 1;" v-else>
						<input type="number" v-model="people_number" placeholder="请输入人数">
					</view>
				</view>
			</view>
			<view class="from-item" v-if="zhiType!=1">
				<view class="from-title">招聘年龄</view>
				<view class="from-small">
					<picker mode="multiSelector" :value="age_require" :range="ageArray" @columnchange="changeByone" @change="bindAgeChange">
						<view class="uni-input" v-if="age_require">{{age_require}}</view>
						<view class="uni-input" v-else>请选择</view>
					</picker>
				</view>
			</view>
			<view class="from-item" v-if="zhiType==1">
				<view class="from-title">预计房量</view>
				<view class="from-small isflex">
					<view class="from-small-left">保底{{info.floor_room}}间</view>
					<input style="flex: 1;" type="number" v-model="expect_room_number" @blur='yuji' placeholder="请输入预计房量">
				</view>
			</view>
			<view class="from-item" v-if="zhiType==1">
				<view class="from-title">做房单价</view>
				<view class="from-small isflex">
					<view class="from-small-left">不能低于{{info.unit_price}}元</view>
					<input style="flex: 1;" type="number" v-model="unit_price" @blur='zuofang' placeholder="请输入做房单价">
				</view>
			</view>
			<view class="from-item" v-if="zhiType==2">
				<view class="from-title">工作时薪</view>
				<view class="from-small isflex">
					<view class="from-small-left isflex">
						<view v-for="(item,index) in wageList" :key="index" class="wage-item" 
							:class="hourly_wage_type==index+1?'active':''" @tap="cutWage(index)">
							{{item}}
						</view>
					</view>
					<view class="" style="flex: 1;">
						<input type="number" v-model="unit_price" @blur='shixin'>
						<!-- <uni-number-box style="float: right;" @blur="bb"  @focus="gg" @change="changeValue_unit_price"  :max="9999" :value="unit_price" /> -->
					</view>
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">工作餐</view>
				<view class="from-small isflex">
					<view class="from-small-left isflex">
						<view v-for="(item,index) in mealList" :key="index" class="wage-item" 
							:class="meal_allowance==index?'active':''" @tap="cutMeal(index)">
							{{item}}
						</view>
					</view>
					<view v-if="meal_allowance==1" style="flex: 1;">
						<input type="number" v-model="meal_allowance_price" @blur='canbu'>
						<!-- <uni-number-box @change="changeValue_meal"  style="float: right;" :min="info.meal_allowance_price" :max="999" :value="meal_allowance_price" /> -->
					</view>
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">住宿</view>
				<view class="from-small isflex">
					<view style="flex: 1;"></view>
					<view class="from-small-left isflex">
						<view v-for="(item,index) in stayList" :key="index" class="wage-item" 
							:class="stay==index?'active':''" @tap="cutStay(index)">
							{{item}}
						</view>
					</view>
				</view>
			</view>
			<view class="from-item">
				<view class="from-title">结算方式</view>
				<view class="from-small">
					<input type="text"  v-model="jiesuan" placeholder="请输入结算方式">
				</view>
			</view>
			<view class="from-item" v-if="zhiType==2">
				<view class="from-title">交通</view>
				<view class="from-small isflex">
					<view class="from-small-left isflex">
						<view v-for="(item,index) in trafficList" :key="index" class="wage-item" 
							:class="traffic_type==index+1?'active':''" @tap="cutTraffic(index)">
							{{item}}
						</view>
					</view>
					<view v-if="traffic_type==2" style="flex: 1;">
						<input type="number" v-model="traffic_price" @blur='jiaotong'>
						<!-- <uni-number-box v-model="traffic_price"  @change="changeValue_traffic_price" style="float: right;" :min="0" :max="999" :value="traffic_price" /> -->
					</view>
				</view>
			</view>
		</view>
		<view class="remark-box">
			<view class="remark-title">备注</view>
			<view class="img-box" v-if="zhiType == 1">
				<view v-for="(item,index) in imgList" :key="index" @tap="upImag1(index)" class="img-item">
					<image :src="item" mode=""></image>
				</view>
				<view class="img-item1" @tap="upImag(0)" v-if="isShang" >
					<image class="main-img1" mode="aspectFit" :src="imgUrl" ></image>
					<view class="main-text">添加图片</view>
				</view>
				<view class="img-length">{{imgList.length}}/3</view>
			</view>
			<textarea  style="width: 100%;" placeholder="请输入备注信息" maxlength="200" name="" id="" v-model="remark"></textarea>
		
		</view>
		<!-- <view style="display: inline-block;" @click="upImag">
			<view v-if="valiFormData.store_photos" class="img-box1">
				<image mode="scaleToFill" :src="fileImg" style="width: 100%;height: 100%;" ></image>
			</view>
			<view v-else class="img-box">
				<image class="main-img1" mode="aspectFit" :src="imgUrl" ></image>
				<text class="main-text">添加图片</text>
			</view>
		</view> -->
		<!-- <view class="">
			<view class="upload-box">
				<view class="img-box">
					<u-upload
						:showProgress="false"
						@on-uploaded="uploadSuccess"
						@on-remove="uploadRemove"
						:action="`${getApp().globalData.url}index/hotelindex/uploadImage`"
						width="160"
						height="160"
						maxCount="3"
					></u-upload>
				</view>
				<view class="max-upload">*最多可以添加3张图片</view>
			</view>
		</view> -->
		<view class="butt">
			<!-- <button v-if="uid" class="but but1" type="default" @click="delClick(uid)">删除</button> -->
			<button class="but" type="default" @click="nowSave" v-if="!order_id">立即下单</button>
			<button class="but" type="default" @click="nowAmend" v-else>修改订单</button>
		</view>
		<view class="service" v-if="isShow">
			<view style="flex: 1;" @tap="isShow = false"></view>
			<view class="service-box">
				<smh-time-range :time="time1" @confrim="confrim" @cancel="cancel"></smh-time-range>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
			    format: true
			})
			return {
				url: '/hotelAdmin/my/address', // 跳转至添加地址路径
				HoList: [],
				array: [],
				active: 0,
				zhiList: [],
				zhi: [],
				man_number: '',
				woman_number: '',
				acZhi: '0',
				zhiType: '',
				num: 1,
				startDay: '',
				endDay: '',
				time: Date.parse(currentDate) / 1000,
				startTime: 0,
				endTime: 0,
				work_time: '',
				mobile: '',
				name:'',
				jiesuan:'下班结算',
				age_require: '',
				daoTime: [
					['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'],
					['00', '30']
				],
				shangTime: [
					['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'],
					['00', '30']
				],
				ageArray: [
					[16,20, 25, 30, 35, 40, 45, 50],
					[25, 30, 35, 40, 45, 50, 55, 60,65,70]
				],
				time: '',
				time1:['00','00','0','23','59'],
				remark: '',
				duty_time: '',
				isShow: false,
				gender_require: 0,
				people_number: '',
				expect_room_number: '',
				unit_price: '',
				mealList: [
					'包餐','餐补'
				],
				meal_allowance: 0,
				meal_allowance_price: 0,
				stayList:[
					'无住宿','包住'
				],
				classList:[
					'客房','餐饮','其他小时工'
				],
				order_class:0,
				stay: 0,
				duty_time_type: 1,
				timeList:[
					'时段', '预计工时'
				],
				
				wageList:[
					'按小时', '按天'
				],
				hourly_wage_type: 1,
				trafficList:[
					'自行到岗','车补'
				],
				traffic_type: 1,
				traffic_price: 0,
				hotel_id: '',
				position_id: '',
				imgUrl:`${getApp().globalData.imgScr}jd/xiangji.png`,
				imgList: [],
				isShang: true,
				info: {},
				cleanliness_standard: [],
				cleaner_rule:'',
				minute: '',
				index: 0,
				order_id: '',
				orderInfo: {},
				hotel_name: '',
			};
		},
		onLoad(options) {
			this.getHolist()
			this.order_id = options.order_id
			if(this.order_id){
				this.getInfo()
			}
			this.num = options.num
			this.active = options.active
			this.startDay = options.startDay
			this.endDay = options.endDay
			this.startTime = Date.parse(options.startDay) / 1000
			this.endTime = Date.parse(options.endDay) / 1000
		},
		computed: {
		    startDate() {
		        return this.getDate('start');
		    },
		    endDate() {
		        return this.getDate('end');
		    }
		},
		onShow() {
			this.mobile = uni.getStorageSync('hotelData').phone
			this.name = uni.getStorageSync('hotelData').real_name ? uni.getStorageSync('hotelData').real_name: uni.getStorageSync('hotelData').nickname
		},
		methods: {
			getInfo(){
				let that = this
				uni.showLoading({
					title: '加载中'
				})
				const params = {
					order_id: that.order_id
				}
				that.$http.post('/index/Hotelorder/order_detail', params).then(res => {
					uni.hideLoading()
					that.getPost(res.hotel_id)
					that.orderInfo = res
					that.age_require = res.age_require
					that.startDay = res.service_start_time
					that.endDay = res.service_end_time
					that.num = res.service_day
					that.mobile = res.mobile
					that.name = res.name
					that.duty_time = res.duty_time
					that.duty_time_type = res.duty_time_type
					that.hotel_id = res.hotel_id
					if(res.gender_require == 0){
						that.people_number = res.people_number
					}else{
						that.man_number = res.people_number[0]
						that.woman_number = res.people_number[1]
					}
	
					that.traffic_price = res.traffic_price
					that.traffic_type = res.traffic_type
					that.unit_price = res.unit_price - 0
					that.work_time = res.work_time
					if(res.order_class == 1){
								that.zhiType = 1
					}else{
								that.zhiType = 2
					}
			
					that.order_class = res.order_class-1
					that.hourly_wage_type = res.hourly_wage_type
					that.remark = res.remarks
					that.position_id = res.position_id
					that.gender_require = res.gender_require
					that.expect_room_number = res.expect_room_number
					that.meal_allowance = res.meal_allowance
					that.meal_allowance_price = res.meal_allowance_price - 0
					that.time = res.time_num
					that.jiesuan = res.jiesuan
					for (let i in res.cleanliness_standard) {
					
						that.imgList.push(`${getApp().globalData.url}`+'uploads/'+res.cleanliness_standard[i])
						that.cleanliness_standard.push(res.cleanliness_standard[i])
					}
					
				
					that.stay = res.stay
				}).catch(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.errMsg,
						icon: "none"
					})
				})
			},
			getqi(){
				console.log(this.zhiList,this.position_id)
				for (let i in this.zhiList) {
					if(this.position_id == this.zhiList[i].id){
						this.acZhi = i
					}
				}
				console.log(this.acZhi)
			},
			getHotelInfo(){
				let that = this
				const params = {
					hotel_id: that.hotel_id
				}
				that.$http.post('/index/Hotelpersonal/hotelinfo', params).then(res => {
					that.info = res
					if(!that.order_id){
						if(that.zhiType == 1){
							that.unit_price = res.unit_price
							that.expect_room_number = res.floor_room
						}else{
							that.unit_price = res.time_unit_price
							that.traffic_price = res.traffic_price
						}
						that.meal_allowance_price = res.meal_price
				
						
					}
				}).catch(res => {
					uni.showToast({
						title: res.errMsg,
						icon: "none"
					})
				})
			},
			startDayChange(e){
				let time = Date.parse(e.detail.value) / 1000
				console.log(time,this.time)
				if(time<this.time){
					uni.showToast({
						title: '当前日期不可选择',
						icon: 'none'
					})
					return
				}
				if(this.endTime<time){
					this.endTime = time
					this.endDay = e.detail.value
				}
				this.startTime = time
				this.startDay = e.detail.value
				this.getNum()
			},
			changeValue_meal(e){
				if(e < this.info.meal_price){
					this.meal_allowance_price = this.info.meal_price
					uni.showToast({
						icon:'none',
						title:'餐补金额不得低于'+this.info.meal_price
					})
				}
			},
			bb(e){
				console.log(e);
			},
			gg(e){
				console.log(e);
			},
			changeValue_unit_price(e){
				let _that = this
				if(e < _that.info.time_unit_price && _that.hourly_wage_type == 1){
		
					uni.showToast({
						icon:'none',
						title:'工作时薪不得低于'+_that.info.time_unit_price
					})
					_that.unit_price = _that.info.time_unit_price
				}
				if(e < _that.info.day_unit_price && _that.hourly_wage_type == 2){
					_that.unit_price = _that.info.day_unit_price
					uni.showToast({
						icon:'none',
						title:'工作时薪不得低于'+_that.info.day_unit_price
					})
				}
			},
			changeValue_traffic_price(e){
				if(e < this.info.traffic_price){
					this.traffic_price = this.info.traffic_price
					uni.showToast({
						icon:'none',
						title:'交通补贴不得低于'+this.info.traffic_price
					})
				}
			},
			endDayChange(e){
				let time = Date.parse(e.detail.value) / 1000
				if(time<this.time){
					uni.showToast({
						title: '当前日期不可选择',
						icon: 'none'
					})
					return
				}
				if(this.startTime>time){
					uni.showToast({
						title: '日期选择至少选择一天',
						icon: 'none'
					})
					return
				}
				this.endTime = time
				this.endDay = e.detail.value
				this.getNum()
			},
			getNum(){
				let num = this.endTime  / 86400 - this.startTime  / 86400
				this.num = num + 1
			},
			cutWage(i){
				if(i==0){
					this.unit_price = this.info.time_unit_price
				}else{
					this.unit_price = this.info.day_unit_price
				}
				this.hourly_wage_type = i+1
			},
			shixin(){
				if(this.hourly_wage_type==1&&this.unit_price<this.info.time_unit_price - 0 ){
					this.unit_price = this.info.time_unit_price
					uni.showToast({
						icon:'none',
						title:'工作时薪不得低于'+this.info.time_unit_price+ '/时'
					})
					return
				}
				if(this.hourly_wage_type==2&&this.unit_price<this.info.day_unit_price - 0 ){
					this.unit_price = this.info.day_unit_price
					uni.showToast({
						icon:'none',
						title:'工作时薪不得低于'+this.info.day_unit_price+ '/天'
					})
					return
				}
			},
			cutTraffic(i){
				this.traffic_type = i + 1
			},
			cutMeal(i){
				this.meal_allowance = i
			},
			cutStay(i){
				this.stay = i
			},
			cutSlass(i){
				this.order_class = i
				if(i == 0){
						
					this.unit_price = this.info.unit_price
					this.zhiType = 1
				}else{
							
					this.unit_price = this.info.time_unit_price
					this.traffic_price = this.info.traffic_price
					this.zhiType = 2
				}
			
			},
			yuji(){
				if(this.expect_room_number<this.info.floor_room){
					this.expect_room_number = this.info.floor_room
					uni.showToast({
						icon:'none',
						title:'保底房量不得低于'+this.info.floor_room
					})
				}
			},
			canbu(){
				if(this.meal_allowance_price<this.info.meal_price){
					this.meal_allowance_price = this.info.meal_price
					uni.showToast({
						icon:'none',
						title:'餐补不得低于'+this.info.meal_price
					})
				}
			},
			jiaotong(){
				if(this.traffic_price<this.info.traffic_price){
					this.traffic_price = this.info.traffic_price
					uni.showToast({
						icon:'none',
						title:'餐补不得低于'+this.info.traffic_price
					})
				}
			},
			shic(){
				if(this.time<this.info.time_min){
					this.time = this.info.time_min
					uni.showToast({
						icon:'none',
						title:'预计时长不得低于'+this.info.time_min
					})
				}
			},
			zuofang(){
				if(this.unit_price<this.info.unit_price - 0 ){
					this.unit_price = this.info.unit_price
					uni.showToast({
						icon:'none',
						title:'做房单价不得低于'+this.info.unit_price
					})
				}
			},
			
			bindPickerChange(e){
				let i = e.detail.value
				if(this.HoList[i].status!==2){
					uni.showToast({
						title: '该酒店暂未审核通过',
						icon: 'none'
					})
					return
				}
				this.active = e.detail.value
				let id = this.HoList[this.active].id
				this.hotel_id = id
				this.getPost(id)
			},
			bindAgeChange(e){
				let arr = e.detail.value
				let i = arr[0]
				let j = arr[1]
				let s = this.ageArray[0][i]
				let o = this.ageArray[1][j]
				this.ageArray = [
					[16,20, 25, 30, 35, 40, 45, 50],
					[25, 30, 35, 40, 45, 50, 55, '不限']
				]
				this.age_require = s + '-' + o
			},
			bindPickerZhi(e){
				this.acZhi = e.detail.value
				this.position_id = this.zhiList[this.acZhi].id
				this.zhiType = this.zhiList[this.acZhi].type
				if(this.zhiType == 1){
		
					this.unit_price = this.info.unit_price
				}else{
			
					this.unit_price = this.info.time_unit_price
					this.traffic_price = this.info.traffic_price
				}
				this.remark = this.cleaner_rule
			},
			cutTime(i){
				this.duty_time_type = i + 1
				this.duty_time = ''
			},
			bindTimeChange(e){
				let i = e.detail.value[0]
				let j = e.detail.value[1]
				let hh = this.daoTime[0][i]
				let ss = this.daoTime[1][j]
				this.work_time = hh+':'+ss
			},
			bindShangChange(e){
				let i = e.detail.value[0]
				let j = e.detail.value[1]
				let hh = this.shangTime[0][i]
				let ss = this.shangTime[1][j]
				this.getEnd(hh,ss)
				this.duty_time = hh+':'+ss
			},
			confrim(e){
				let hh = e.time.substring(0,2)
				let ss = e.time.substring(3,5)
				this.getEnd(hh,ss)
				this.duty_time = e.time
				this.work_time = ''
				this.isShow = false
				this.$forceUpdate()
			},
			getEnd(h,s){
				let arr =[
					['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'],
					['00', '30']
				]
				let m = 0
				for (let i in arr[0]) {
					if(h==arr[0][i]){
						m = i - 0 + 1
						this.daoTime[0] = arr[0].slice(0,m)
					}
				}
				this.index = m
				this.minute = s
			},
			cancel(e){
				this.isShow = false
			},
			changeTime(e){
				if(e.detail.column==0){
					if(e.detail.value==this.index-1&&this.minute=='00'){
						this.daoTime[1] = ['00']
					}else{
						this.daoTime[1] = ['00','30']
					}
				}
				this.$forceUpdate()
			},
			changeByone(e){
				switch (e.detail.column) {
					case 0: //拖动第1列
						switch (e.detail.value) {
							case 0:
								this.ageArray[1] = [25, 30, 35, 40, 45, 50, 55,'不限']
								break
							case 1:
								this.ageArray[1] = [30, 35, 40, 45, 50, 55,'不限']
								break
							case 2:
								this.ageArray[1] = [35, 40, 45, 50, 55,'不限']
								break
							case 3:
								this.ageArray[1] = [40, 45, 50, 55,'不限']
								break
							case 4:
								this.ageArray[1] = [45, 50, 55,'不限']
								break
							case 5:
								this.ageArray[1] = [50, 55,'不限']
								break
							case 6:
								this.ageArray[1] = [55,'不限']
								break
							case 7:
								this.ageArray[1] = ['不限']
								break
						}
						break
				}
				this.$forceUpdate()
			},
			async upImag(i) {
				let _this = this
				try{
					let res = await uni.chooseImage()
					if(res[0]) throw new Error(JSON.stringify(res[0]))
					 let tempFilePaths = res[1].tempFilePaths;
					 uni.showLoading({
					 	title: '图片上传中....',
						mask:true,
					 });
					 let rep = await uni.uploadFile({
				            // url: 'https://www.zhuoxianrenli.cn/index/hotelindex/uploadImage', //图片上传接口
				            url: `${getApp().globalData.url}index/hotelindex/uploadImage`, //图片上传接口
				            filePath: tempFilePaths[0],
				            name: 'file',
							header: {
							"Content-Type": "multipart/form-data",
							},
						})
					// 根据接口具体返回格式   赋值具体对应url
					let url = `${getApp().globalData.url}`+'uploads/'+JSON.parse(rep[1].data).file
					this.cleanliness_standard.push(JSON.parse(rep[1].data).file)
					this.imgList.push(url)
					if(this.imgList.length==3){
						this.isShang = false
					}
					console.log(this.imgList,123)
					uni.hideLoading()
				}catch(e){
					console.log('e =========>',e);
					uni.hideLoading()
					//TODO handle the exception
					if(e.message && JSON.parse(e.message)) {
						// 取消图片选择
					}else {
						uni.showToast({
							title:e.errMsg,
							icon:"none"
						})
					}
				}
			},
			async upImag1(i) {
				let _this = this
				try{
					let res = await uni.chooseImage()
					if(res[0]) throw new Error(JSON.stringify(res[0]))
					 let tempFilePaths = res[1].tempFilePaths;
					 if(i == 0) this.imgList[0] = tempFilePaths[0]
					 if(i == 1) this.imgList[1] = tempFilePaths[0]
					 if(i == 2) this.imgList[2] = tempFilePaths[0]
					 uni.showLoading({
					 	title: '图片上传中....',
						mask:true,
					 });
					 let rep = await uni.uploadFile({
				            // url: 'https://www.zhuoxianrenli.cn/index/hotelindex/uploadImage', //图片上传接口
				            url: `${getApp().globalData.url}index/hotelindex/uploadImage`, //图片上传接口
				            filePath: tempFilePaths[0],
				            name: 'file',
							header: {
							"Content-Type": "multipart/form-data",
							},
						})
					// 根据接口具体返回格式   赋值具体对应url
					for (let j in this.imgList) {
						if(j==i){
							this.imgList[j] = `${getApp().globalData.url}`+'uploads/'+JSON.parse(rep[1].data).file
							this.cleanliness_standard[j] = JSON.parse(rep[1].data).file
						}
					}
					console.log(this.imgList,123)
					uni.hideLoading()
					this.$forceUpdate()
				}catch(e){
					console.log('e =========>',e);
					uni.hideLoading()
					//TODO handle the exception
					if(e.message && JSON.parse(e.message)) {
						// 取消图片选择
					}else {
						uni.showToast({
							title:e.errMsg,
							icon:"none"
						})
					}
				}
			},
			
			changeSex(e){
				if(e.detail.value){
					this.gender_require = 1
				}else{
					this.gender_require = 0
				}
			},
			getHolist(){
				const params = {
					
				}
				this.$http.post('/index/Hotelpersonal/hotellist', params).then(res => {
					this.HoList = res
					for (let i in this.HoList) {
						this.array.push(this.HoList[i].hotel_name)
					}
					let id = this.HoList[this.active].id
					this.hotel_id = id
		
					this.getPost(this.hotel_id)
				}).catch(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.errMsg,
						icon: "none"
					})
				})
			},
			// 清洁要求
			configData() {
				let _this = this
				this.$http.get('/index/Communal/config_data', {
					config_id: 6
				}).
				then(res => {
					_this.cleaner_rule = res.cleaner_rule.value
					if(!that.order_id){
										_this.remark = res.cleaner_rule.value
					}
	
					
					//_this.remark = res.cleaner_rule.value
						//console.log(_this.zhiType)
					console.log('res', res)
				})
			},
			getPost(id){
				this.zhi = []
				this.zhiList = []
				const params = {
					hotel_id: id
				}
				this.$http.post('/index/Hotelpersonal/position_list', params).then(res => {
					this.zhiList = res
					if(this.order_id){
						this.getqi()
					}
					for (let i in this.zhiList) {
						this.zhi.push(this.zhiList[i].name)
					}
					this.position_id = this.zhiList[this.acZhi].id
					if(!this.order_id){
						this.zhiType = this.zhiList[this.acZhi].type	
					}
					if(this.zhiType == 1){
						this.order_class = 0
					}else{
						this.order_class = 1
					}

					this.configData()
					this.getHotelInfo()
				}).catch(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.errMsg,
						icon: "none"
					})
				})
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			checkPhoneNumber(phoneNumber){
				var regexp = /^((1[3,5,6,7,8,9][0-9])|(14[5,7])|(17[0,6,7,8])|(19[1,7]))\d{8}$/
				return regexp.test(phoneNumber)
			},
			/**
			 * 保存按钮事件
			 * 简单判断了输入的房间号的合法性
			 * 保存时 即添加房间
			 */
			nowSave(){
				if(!this.checkPhoneNumber(this.mobile)&&this.mobile==''){
					uni.showToast({
						icon:'none',
						title:'请填写正确的手机号'
					})
					return
				}
				if(this.zhiType==1){
					if(this.expect_room_number<this.info.floor_room){
						uni.showToast({
							icon:'none',
							title:'保底房量不得低于'+this.info.floor_room
						})
						return
					}
					if(this.unit_price<this.info.unit_price - 0 ){
						uni.showToast({
							icon:'none',
							title:'做房单价不得低于'+this.info.unit_price
						})
						return
					}
					if(this.meal_allowance == 1 && this.meal_allowance_price< this.info.meal_price ){
						this.meal_allowance_price = this.info.meal_price
						uni.showToast({
							icon:'none',
							title:'餐补金额不得低于'+this.info.meal_price
						})
						return
					}
				}else{
					if(this.duty_time_type == 2 &&  this.time< this.info.time_min){
						this.time = this.info.time_min
						uni.showToast({
							icon:'none',
							title:'预计时长不得低于'+this.info.time_min
						})
						return
					}
					if(this.hourly_wage_type == 1 &&  this.unit_price< this.info.time_unit_price){
						this.unit_price = this.info.time_unit_price
						uni.showToast({
							icon:'none',
							title:'工作时薪不得低于'+this.info.time_unit_price
						})
						return
					}
					if(this.hourly_wage_type == 2 &&  this.unit_price< this.info.day_unit_price){
						this.unit_price = this.info.day_unit_price
						uni.showToast({
							icon:'none',
							title:'工作时薪不得低于'+this.info.day_unit_price
						})
						return
					}
					if(this.meal_allowance == 1 &&  this.meal_allowance_price< this.info.meal_price){
						this.meal_allowance_price = this.info.meal_price
						uni.showToast({
							icon:'none',
							title:'餐补不得低于'+this.info.meal_price
						})
						return
					}
					if(this.traffic_type == 2 &&  this.traffic_price< this.info.traffic_price){
						this.traffic_price = this.info.traffic_price
						uni.showToast({
							icon:'none',
							title:'交通补不得低于'+this.info.traffic_price
						})
						return
					}
				}
				let cleanliness_standard = this.cleanliness_standard.join(',')
				uni.showLoading({
					title: '下单中...',
					mask: true
				})
				let number = ''
				if(this.gender_require==1){
					number= this.man_number+','+this.woman_number
				}else{
					number = this.people_number
				}
				let order_class = this.order_class +1
				const params = {
					order_class: order_class,
					service_start_time: this.startDay,
					service_end_time: this.endDay,
					service_day: this.num,
					hotel_id: this.hotel_id,
					hourly_wage_type: this.hourly_wage_type,
					age_require: this.age_require,
					cleanliness_standard: cleanliness_standard,
					remark: this.remark,
					position_id: this.position_id,
					duty_time_type:this.duty_time_type,
					duty_time: this.duty_time,
					mobile: this.mobile,
					name:this.name,
					work_time: this.work_time,
					gender_require: this.gender_require,
					people_number: number,
					expect_room_number: this.expect_room_number,
					unit_price: this.unit_price,
					meal_allowance: this.meal_allowance,
					meal_allowance_price: this.meal_allowance_price,
					time: this.time,
					stay: this.stay,
					traffic_type: this.traffic_type,
					traffic_price: this.traffic_price,
					jiesuan:this.jiesuan
				}
				this.$http.post('/index/Hotelindex/add_order', params).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: '下单成功'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tag/indent/dqg'
						});
					}, 1500)
				}).catch(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.errMsg,
						icon: "none"
					})
				})
			},
			nowAmend(){
				if(!this.checkPhoneNumber(this.mobile)&&this.mobile==''){
					uni.showToast({
						icon:'none',
						title:'请填写正确的手机号'
					})
					return
				}
				if(this.zhiType==1){
					if(this.expect_room_number<this.info.floor_room){
						uni.showToast({
							icon:'none',
							title:'保底房量不得低于'+this.info.floor_room
						})
						return
					}
					if(this.unit_price<this.info.unit_price - 0 ){
						uni.showToast({
							icon:'none',
							title:'做房单价不得低于'+this.info.unit_price
						})
						return
					}
					if(this.meal_allowance == 1 && this.meal_allowance_price< this.info.meal_price ){
						this.meal_allowance_price = this.info.meal_price
						uni.showToast({
							icon:'none',
							title:'餐补金额不得低于'+this.info.meal_price
						})
						return
					}
				}else{
					if(this.duty_time_type == 2 &&  this.time< this.info.time_min){
						this.time = this.info.time_min
						uni.showToast({
							icon:'none',
							title:'预计时长不得低于'+this.info.time_min
						})
						return
					}
					if(this.hourly_wage_type == 1 &&  this.unit_price< this.info.time_unit_price){
						this.unit_price = this.info.time_unit_price
						uni.showToast({
							icon:'none',
							title:'工作时薪不得低于'+this.info.time_unit_price
						})
						return
					}
					if(this.hourly_wage_type == 2 &&  this.unit_price< this.info.day_unit_price){
						this.unit_price = this.info.day_unit_price
						uni.showToast({
							icon:'none',
							title:'工作时薪不得低于'+this.info.day_unit_price
						})
						return
					}
					if(this.meal_allowance == 1 &&  this.meal_allowance_price< this.info.meal_price){
						this.meal_allowance_price = this.info.meal_price
						uni.showToast({
							icon:'none',
							title:'餐补不得低于'+this.info.meal_price
						})
						return
					}
					if(this.traffic_type == 2 &&  this.traffic_price< this.info.traffic_price){
						this.traffic_price = this.info.traffic_price
						uni.showToast({
							icon:'none',
							title:'交通补不得低于'+this.info.traffic_price
						})
						return
					}
				}
				let cleanliness_standard = this.cleanliness_standard.join(',')
				uni.showLoading({
					title: '下单中...',
					mask: true
				})
				let number = ''
				if(this.gender_require==1){
					number= this.man_number+','+this.woman_number
				}else{
					number = this.people_number
				}
				let order_class = this.order_class +1
				const params = {
					order_class: order_class,
					service_start_time: this.startDay,
					service_end_time: this.endDay,
					service_day: this.num,
					hotel_id: this.hotel_id,
					hourly_wage_type: this.hourly_wage_type,
					age_require: this.age_require,
					cleanliness_standard: cleanliness_standard,
					remark: this.remark,
					position_id: this.position_id,
					duty_time_type:this.duty_time_type,
					duty_time: this.duty_time,
					mobile: this.mobile,
					name:this.name,
					work_time: this.work_time,
					gender_require: this.gender_require,
					people_number: number,
					expect_room_number: this.expect_room_number,
					unit_price: this.unit_price,
					meal_allowance: this.meal_allowance,
					meal_allowance_price: this.meal_allowance_price,
					time: this.time,
					stay: this.stay,
					traffic_type: this.traffic_type,
					traffic_price: this.traffic_price,
					order_id: this.order_id,
					jiesuan:this.jiesuan
				}
				this.$http.post('/index/Hotelindex/edit_order', params).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: '修改订单成功'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tag/indent/dqg'
						});
					}, 1500)
				}).catch(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.errMsg,
						icon: "none"
					})
				})
			},
			async save(ref) {
				let _this = this
				uni.showLoading({
					title: '下单中...',
					mask: true
				})
				try {
					let res = await this.$refs[ref].validate()
		
					if (res.subsidy == '') res.subsidy = 0
					// res.room_type_ids = res.room_type_ids.join(',')
					res.age_require = res.age_require.join('-')
					res.level_require = res.level_require.join(',')
					res.name = _this.name
					res.address_id = _this.valiFormData.address_id
					await this.$http.post('/index/Hotelindex/add_order', res)

					uni.hideLoading()
					uni.showToast({
						title: '下单成功',
						icon: "none"
					})

					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tag/indent/indent'
						});
					}, 1500)
				} catch (err) {
					uni.hideLoading()
					if (Array.isArray(err) && err.length > 0) {
						uni.showToast({
							title: err[0].errorMessage,
							icon: "none"
						})
					} else if (err.errMsg) {
						uni.showToast({
							title: err.errMsg,
							icon: "none"
						})
					}
				}
			},
		},
	}
</script>

<style lang="scss">
	.p-home {
		box-sizing: border-box;
		overflow: hidden;
	}
	.from-box .from-item{
		border-top:1rpx solid rgba(230, 230, 230, 0.54)!important;
	}
	.hotel-top{
		height: 100rpx;
		background-color: #fff;
		align-items: center;
		margin-bottom: 16rpx;
		padding: 0 30rpx;
	}
	.from-box{
		background-color: #fff;
		padding: 0 30rpx;
		.from-item{
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			color: #2E2E2E;
			border-top: 2rpx solid #C8C8C8;
			display: flex;
			justify-content: space-between;
			.from-title{
				width: 5em;
			}
			.from-small{
				flex: 1;
				text-align: right;
				align-items: center;
				input{
					height: 100%;
				}
				.from-small-left{
					width: 270rpx;
					text-align: left;
					font-size: 26rpx;
					color: #676767;
				}
			}
		}
	}
	.butt {
		display: flex;
		justify-content: center;
		align-items: center;
		box-sizing: border-box;
		width: 100%;
		background-color: #ffffff;
		padding: 44rpx 24rpx;
	
		.but {
			flex: 1;
			line-height: 80rpx;
			border-radius: 40rpx;
			background: linear-gradient(-90deg, #8dc9f1, #d8eefc);
			font-size: 32rpx;
			color: #FFFFFF;
			// margin: 0 20rpx;
		}
	
		.but1 {
			color: #000000;
			background: linear-gradient(-90deg, #ffffff, #ffffff);
		}
	
		.but::after {
			display: none;
		}
	}
	.place-top{
		display: flex;
		justify-content: space-between;
		background-color: #fff;
		padding: 30rpx;
		view{
			flex: 1;
		}
		.place-start,
		.place-end{
			text-align: left;
			font-size: 24rpx;
			color: #676767;
		}
		.picker{
			font-size: 34rpx;
			color: #000;
			font-weight: 600;
			margin-top: 10rpx;
		}
		.place-text{
			text-align: center;
			line-height: 100rpx;
			font-size: 24rpx;
		}
	}
	.service{
		background-color: rgba(0,0,0,0.5);
		position: fixed;
		z-index: 9999;
		width: 100%;
		height: 100vh;
		top: 0;
		left: 0;
		display: flex;
		.service-box{
			width: 100%;
			height: 500rpx;
			position: absolute;
			left: 0;
			z-index: 99999;
			bottom: 0;
			background-color: #fff;
			border-radius: 13rpx 13rpx 0 0;
			overflow: hidden;
		}
	}
	.isflex{
		display: flex;
		justify-content: space-between;
		align-items: center;
		input{
			height: 100%;
		}
	}
	.wage-item{
		width: 132rpx;
		height: 64rpx;
		text-align: center;
		line-height: 64rpx;
		font-size: 26rpx;
		color: #202020;
		border-radius: 6rpx;
		background-color: #E9E9E9;
	}
	.active{
		background-color: #D8EEFC;
		color: #fff;
	}
	.remark-box{
		width: 100%;
		padding: 0 30rpx;
		background-color: #fff;
		margin-top: 16rpx;
		.remark-title{
			height: 84rpx;
			line-height: 84rpx;
			border-bottom: 2rpx solid #C8C8C8;
			font-size: 32rpx;
			color: #2E2E2E;
		}
		.img-box{
			display: flex;
			height: 200rpx;
			padding-top: 20rpx;
			position: relative;
			.img-item{
				width: 160rpx;
				height: 160rpx;
				margin-right: 20rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.img-item1{
				width: 160rpx;
				height: 160rpx;
				background-color: #F5F7FD;
				border-radius: 13rpx;
				color: #c5c7cc;
				text-align: center;
				font-size: 24rpx;
				image{
					width: 58rpx;
					height: 52rpx;
					margin: 20rpx 0;
				}
			}
			.img-length{
				position: absolute;
				right: 0;
				top: 0;
				z-index: 22;
				font-size: 32rpx;
				color: #C7C7C7;
			}
		}
	}
	.ellipsis1{
		overflow: hidden;
		white-space: nowrap; /* 防止文字换行 */
		text-overflow: ellipsis;
	}
	.hotel-title{
		width: 100%;
		text-align: center;
		font-size: 32rpx;
		background-color: #fff;
		height: 100rpx;
		line-height: 100rpx;
	}
</style>
